script_enemy_main{

let effect1=0;
let object1=[];
let xscale1=0.01;
let yscale1=0.01;
let xscale2=0.01;
let yscale2=0.01;

let phase1=rand_int(0,1);
let phase=1;

let angle1=0;
let shot1=0;
let bullet1=[];

let angle2=0;
let color2=0;

let phase4angle=rand(0,360);

let hpos1=-GetClipMinX;
let hpos2=GetClipMaxX/2;
let phase5shift=0;

let angle=rand(0,360);
let color=0;

let bgchange1=0;
let bgchange2=0;
let bgfade1=0;
let bgfade2=0;
let bgpicture1=0;
let bgpicture2=-384;
let bgchanged1=0;
let bgchanged2=0;

let character="Tomoko";
let cutin=character;
let dispelled=0;
let spellcards=1;
let spellcardnumber=70;
let damagerate=10;
let outfit=1;
outfit=(128*outfit)-128;
let usespell=0;
let bgfade=0;
let frame=0;
let time=0;
let miny=GetClipMinY; let maxy=GetClipMaxY; let minx=GetClipMinX; let maxx=GetClipMaxX;
let cx=GetCenterX; let cy=GetCenterY;

let SEshots4=("\script\SoundEffects\shots4.wav");
let SElaserm3=("script\SoundEffects\laserm3.wav");
let SEmagics5=("\script\SoundEffects\magics5.wav");
let SElaserm2=("\script\SoundEffects\laserm2.wav");
let SEshotb7=("\script\SoundEffects\shotb7.wav");
let SEcharge1=("script\SoundEffects\charge1.wav");

let EFwings=("\script\Images\OtherEffects\ButterflyWings.png");

let BG1=("\script\Images\BackgroundLayers\Tomoko7a.png");
let GRboss=("\script\Images\CharacterSprites\Tomoko.png");

#include_function "script/Functions/SetSpellcardCommonData.txt";
#include_function "script/Functions/SpellcardNameLoad.txt";
#include_function "script/Functions/HealthBarLoad.txt";
#include_function "script/Functions/CutInLoad.txt";

@Initialize{
	LoadUserShotData("script\shots\ShotsTomoko2.txt");
	
	LoadSE("\script\SoundEffects\shots4.wav");
	LoadSE("script\SoundEffects\laserm3.wav");
	LoadSE("\script\SoundEffects\magics5.wav");
	LoadSE("\script\SoundEffects\laserm2.wav");
	LoadSE("\script\SoundEffects\shotb7.wav");
	LoadSE("script\SoundEffects\charge1.wav");
	LoadGraphic("\script\Images\OtherEffects\ButterflyWings.png");
	
	LoadGraphic("\script\Images\BackgroundLayers\Tomoko7a.png");
	LoadGraphic("\script\Images\CharacterSprites\Tomoko.png");

	SetScore(2500000);
	SetLife(1100);
	SetTimer(95);
	SetInvincibility(120);
	SetDamageRate(10,10);
	SetEnemyMarker(true);
	MagicCircle(true);
	#include_function "script/Functions/Focus.txt";
	Focus(character);
	SetEffectForZeroLife(60,100,1);
	SetMovePosition02(cx,cy-100,50);

	SetDurableSpellCard;
}
	
@MainLoop{

SetCollisionA(GetX,GetY,16);
SetCollisionB(GetX,GetY,16);
SetShotAutoDeleteClip(32,32,32,32);

Weakness(character);
#include_function "script/Functions/Weakness.txt";
if(GetCommonData("BombOn")==0){ damagerate=10; }
if(GetCommonData("BombOn")==1){ damagerate=0; }
SetDamageRate(damagerate*weaken,damagerate*weaken);

let difficulty="";
if(GetCommonDataDefault("Difficulty",2)==1){ difficulty="Easy"; }
if(GetCommonDataDefault("Difficulty",2)==2){ difficulty="Normal"; }
if(GetCommonDataDefault("Difficulty",2)==3){ difficulty="Hard"; }
if(GetCommonDataDefault("Difficulty",2)==4){ difficulty="Lunatic"; }

SpellcardName("Artificial Evolution [Monolith]",spellcardnumber); 
HealthBar();
Portrait(cutin,1);



if(time==90){
	loop(2){
	effect1=(Obj_Create(OBJ_EFFECT));
	Obj_SetPosition(effect1,GetX,GetY);
	ObjEffect_SetScale(effect1,xscale1,yscale1);
	ObjEffect_SetLayer(effect1,1); ObjEffect_SetTexture(effect1,EFwings); ObjEffect_SetRenderState(effect1,ADD);
	ObjEffect_SetPrimitiveType(effect1,PRIMITIVE_TRIANGLESTRIP); ObjEffect_CreateVertex(effect1,4);
	ObjEffect_SetVertexXY(effect1,0,-190,-100); ObjEffect_SetVertexUV(effect1,0,0,0);
	ObjEffect_SetVertexXY(effect1,1,190,-100); ObjEffect_SetVertexUV(effect1,1,380,0);
	ObjEffect_SetVertexXY(effect1,2,-190,100); ObjEffect_SetVertexUV(effect1,2,0,200);
	ObjEffect_SetVertexXY(effect1,3,190,100); ObjEffect_SetVertexUV(effect1,3,380,200);
	ObjEffect_SetVertexColor(effect1,0,180,255,255,255); ObjEffect_SetVertexColor(effect1,1,180,255,255,255);
	ObjEffect_SetVertexColor(effect1,2,180,255,255,255); ObjEffect_SetVertexColor(effect1,3,180,255,255,255);
	object1=object1~[effect1];
	}
}

if(time>=90){
	if(xscale1<1){ xscale1+=(xscale1*0.1); }
	if(yscale1<1){ yscale1+=(yscale1*0.2); }
	if(xscale2<1.1){ xscale2+=(xscale2*0.09); }
	if(yscale2<1.2){ yscale2+=(yscale2*0.18); }
	Obj_SetPosition(object1[0],GetX,GetY-30);
	ObjEffect_SetScale(object1[0],xscale1,yscale1);
	ObjEffect_SetVertexColor(object1[0],0,200,0,255,255); ObjEffect_SetVertexColor(object1[0],1,200,0,255,255);
	ObjEffect_SetVertexColor(object1[0],2,200,255,255,255); ObjEffect_SetVertexColor(object1[0],3,200,255,255,255);
	Obj_SetPosition(object1[1],GetX,GetY-30);
	ObjEffect_SetScale(object1[1],xscale2+0.1*cos(time*2),yscale2+0.2*cos(time*2));
	ObjEffect_SetVertexColor(object1[1],0,200,255,100,255); ObjEffect_SetVertexColor(object1[1],1,200,255,100,255);
	ObjEffect_SetVertexColor(object1[1],2,50,255,100,255); ObjEffect_SetVertexColor(object1[1],3,50,255,100,255);
}


if((time+150)%290==0 && time>=90){
	CreateEnemyFromFile(GetCurrentScriptDirectory~"Tomoko - Monolith - Familiar.txt",GetX,GetY,0,0,[90+30*cos(angle),phase1]);
phase1++;
angle+=rand(60,120);
}


if(time%300==0 && time>=90){ phase++; if(phase>5){ phase=1; } }
if((time+90)%300==0 && time>=90){
	SetColor(255,100,255);
	Concentration01(90);
	SetColor(255,255,255);
PlaySE(SEcharge1);
}

if(phase==1 && time==90){
	loop(3){
	shot1=(Obj_Create(OBJ_SHOT));
	Obj_SetPosition(shot1,GetX+100*cos(time+0),GetY+40*sin(time+0));
	Obj_SetAngle(shot1,0);
	Obj_SetAutoDelete(shot1,false);
	ObjShot_SetBombResist(shot1,true);
	ObjShot_SetGraphic(shot1,45);
	bullet1=bullet1~[shot1];
	}
	loop(3){
	shot1=(Obj_Create(OBJ_SHOT));
	Obj_SetPosition(shot1,GetX+100*cos(time+0),GetY+40*sin(time+0));
	Obj_SetAngle(shot1,0);
	Obj_SetAutoDelete(shot1,false);
	ObjShot_SetBombResist(shot1,true);
	ObjShot_SetGraphic(shot1,46);
	bullet1=bullet1~[shot1];
	}
}

if(phase==1 && time>=90){
	Obj_SetPosition(bullet1[0],GetX+100*cos(time+0),GetY+40*sin(time+0));
	Obj_SetPosition(bullet1[1],GetX+100*cos(time+120),GetY+40*sin(time+120));
	Obj_SetPosition(bullet1[2],GetX+100*cos(time+240),GetY+40*sin(time+240));

	Obj_SetAngle(bullet1[0],time+90);
	Obj_SetAngle(bullet1[1],time+210);
	Obj_SetAngle(bullet1[2],time+330);

	Obj_SetPosition(bullet1[3],GetX-70*cos(time+0),GetY+20*sin(time+0));
	Obj_SetPosition(bullet1[4],GetX-70*cos(time+120),GetY+20*sin(time+120));
	Obj_SetPosition(bullet1[5],GetX-70*cos(time+240),GetY+20*sin(time+240));

	Obj_SetAngle(bullet1[3],-time+90);
	Obj_SetAngle(bullet1[4],-time+330);
	Obj_SetAngle(bullet1[5],-time+210);
angle1+=3;
}

if(phase==1 && time%3==0 && length(bullet1)>=5){
	CreateShot02(Obj_GetX(bullet1[0]),Obj_GetY(bullet1[0]),10,angle1,-0.3,2.5,57,25);
	CreateShot02(Obj_GetX(bullet1[1]),Obj_GetY(bullet1[1]),10,angle1+120,-0.3,2.5,57,25);
	CreateShot02(Obj_GetX(bullet1[2]),Obj_GetY(bullet1[2]),10,angle1+240,-0.3,2.5,57,25);

	CreateShot02(Obj_GetX(bullet1[3]),Obj_GetY(bullet1[3]),10,-angle1+245,-0.3,2.5,58,25);
	CreateShot02(Obj_GetX(bullet1[4]),Obj_GetY(bullet1[4]),10,-angle1+125,-0.3,2.5,58,25);
	CreateShot02(Obj_GetX(bullet1[5]),Obj_GetY(bullet1[5]),10,-angle1+5,-0.3,2.5,58,25);
PlaySE(SEshots4);
}

let i=0;
while(i<length(bullet1)){
		if(phase!=1){ Obj_SetAlpha(bullet1[i],0); }
		if(phase==1){ Obj_SetAlpha(bullet1[i],255); }
	i++;
}

//===============================================================

if(phase==2){
	if(frame==1){
		angle2=GetAngleToPlayer;
		color2=rand_int(1,10);
	PlaySE(SElaserm3);
	}
	if(frame>0 && frame<=8){
		loop(25){
		CreateShot02(GetX,GetY-10,0,angle2,0.1,10,70+color2,0);
		angle2+=360/25;
		}
	color2+=1;
	if(color2>10){ color2=1; }
	usespell=-20;
	}

	if(frame>=25){ frame=0; }
}

//===============================================================

if(phase==3){
	if(time%3==0){
	let angle=time;
		loop(4){
		CreateShot02(GetX+15,GetY-45,rand(2,6),angle,-0.1,rand(1.7,2.3),rand_int(100,101),0);
		CreateShot02(GetX+15,GetY-45,rand(2,6),-(angle*1.15)+180,-0.1,rand(1.7,2.3),rand_int(100,101),0);
		angle+=360/4;
		}
	usespell=15;
	}
	if(time%5==0){ PlaySE(SEmagics5); }
}

//===============================================================

if(phase==4 && time%6==0){
let x=0;
	loop(10){
		CreateShot01(GetX,GetY,2,phase4angle,81,0+x);
		CreateShot01(GetX,GetY,2,12.5+phase4angle+180,81,16-x);
	phase4angle+=1.2;
	x+=1;
	}
usespell=-10;
phase4angle+=13.5;
PlaySE(SElaserm2);
}

//===============================================================

if(phase==5 && (time+0)%20==0){
phase5shift=rand(70,90);
	CreateShot02(minx+hpos1,miny,2,90,0.015,4,rand_int(119,121),20);
	hpos1+=phase5shift;
	if(hpos1>maxx){ hpos1-=maxx+40; }
PlaySE(SEshotb7);
usespell=20;
}
if(phase==5 && (time+10)%20==0){
	CreateShot02(minx+hpos2,miny,2,90,0.015,4,rand_int(119,121),20);
	hpos2+=phase5shift;
	if(hpos2>maxx){ hpos2-=maxx+40; }
PlaySE(SEshotb7);
usespell=20;
}

//===============================================================


if((time-90)%280==0){ bgchange1=1; bgchange2=0; bgchanged1=0; }
if((time+50)%280==0){ bgchange2=1; bgchange1=0; bgchanged2=0; }

if(bgchange1==1 && bgpicture1<4400){
	if(bgfade1<180){ bgfade1+=5; }
	if(bgfade2>0){ bgfade2-=5; }
	if(bgfade2==0 && bgchanged2==0){ bgpicture2+=384; bgchanged2=1; }
}
if(bgchange2==1 && bgpicture2<4400){
	if(bgfade2<180){ bgfade2+=5; }
	if(bgfade1>0){ bgfade1-=5; }
	if(bgfade1==0 && bgchanged1==0){ bgpicture1+=384; bgchanged1=1; }
}


time++; frame++;
if(usespell>0){ usespell--; } if(usespell<0){ usespell++; }
SetCommonData("Boss1X",GetX); SetCommonData("Boss1Y",GetY);

#include_function "script/Functions/SpellcardName.txt";
#include_function "script/Functions/HealthBar.txt";
#include_function "script/Functions/CutIn.txt";

if(GetLife==0 && dispelled==0){ CreateEnemyFromFile("script\Functions\dispel.txt",GetX,GetY,0,0,character); dispelled=1; }
}

@BackGround{
if(bgfade<130){ bgfade+=5; }
	SetGraphicRect(0+bgpicture1,0,192+bgpicture1,224);
	SetGraphicScale(2,2);
	SetRenderState(ALPHA);
	SetTexture(BG1);
	SetAlpha(bgfade1);
	SetGraphicAngle(0,0,0);
	DrawGraphic(cx,cy);

	SetGraphicRect(192+bgpicture2,0,384+bgpicture2,224);
	SetGraphicScale(2,2);
	SetRenderState(ALPHA);
	SetTexture(BG1);
	SetAlpha(bgfade2);
	SetGraphicAngle(0,0,0);
	DrawGraphic(cx,cy);
}

@DrawLoop{
	SetGraphicScale(1,1);
	SetTexture(GRboss);
	SetGraphicAngle(0,0,0);
	SetColor(255,255,255);
	SetRenderState(ALPHA);

	if(usespell>=1){ SetGraphicRect(384,outfit,512,outfit+128); }
	if(usespell<=-1){ SetGraphicRect(512,outfit,640,outfit+128); }
	if(usespell==0){
		if(GetSpeedX<=0.5 && GetSpeedX>=-0.5){ SetGraphicRect(0,outfit,128,outfit+128); }
		else if(GetSpeedX<-0.5){ SetGraphicRect(128,outfit,256,outfit+128); }
		else if(GetSpeedX>0.5){ SetGraphicRect(256,outfit,384,outfit+128); }
	}
	DrawGraphic(GetX,GetY);
}

@Finalize{
	if(GotSpellCardBonus){ SetCommonData("LastTrumpCard",3); }
	NewPointData(spellcardnumber,7);
	#include_function "script/Functions/Main Menu/SpellcardDataAndPoints.txt";
}

}